package com.example.kiratest.test;

import com.aliyun.tea.*;
import lombok.extern.slf4j.Slf4j;

//机器人发送互动卡片普通版
@Slf4j
public class CommonPushCard {

    /**
     * <b>description</b> :
     * <p>使用 Token 初始化账号Client</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.dingtalkim_1_0.Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
        config.protocol = "https";
        config.regionId = "central";
        return new com.aliyun.dingtalkim_1_0.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dingtalkim_1_0.Client client = CommonPushCard.createClient();
        com.aliyun.dingtalkim_1_0.models.SendRobotInteractiveCardHeaders sendRobotInteractiveCardHeaders = new com.aliyun.dingtalkim_1_0.models.SendRobotInteractiveCardHeaders();
        sendRobotInteractiveCardHeaders.xAcsDingtalkAccessToken = "f36a339c3ca63ae2adcb363bf0a0e6cf";//得到dingtalk平台的accessToken

        com.aliyun.dingtalkim_1_0.models.SendRobotInteractiveCardRequest sendRobotInteractiveCardRequest = new com.aliyun.dingtalkim_1_0.models.SendRobotInteractiveCardRequest()
                .setCardData("{\"\"title\":\"标题\",\"text\":\"这是我的文本\"\"}")
                .setCardBizId("1743132733793")
                .setCardTemplateId("04c612f3-f11a-4bcd-83e0-d9074e483d98.schema")
                .setRobotCode("dingzrr5q24mlutd6knl")
                ;
        try {
            client.sendRobotInteractiveCardWithOptions(sendRobotInteractiveCardRequest, sendRobotInteractiveCardHeaders, new com.aliyun.teautil.models.RuntimeOptions());
        } catch (TeaException err) {
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                log.info("code:{}",err);

                log.info("code:{}",err.message
                );
            }

        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                log.info("code:{}",err.code);

                log.info("code:{}",err.message);
            }

        }        
    }
}
